const all = function (promiseList) {
    const valuesList = [];
    const promisesLength = promiseList.length;
    let count = 0;

    return new Promise((resolve, reject) => {
        for (let i = 0; i < promisesLength; i++) {
            // 数组参数如果不是Promise实例，先调用Promise.resolve
            // 如果参数是 Promise 实例，那么Promise.resolve将不做任何修改、原封不动地返回这个实例
            Promise.resolve(promiseList[i]).then(res => {
                count++;
                valuesList[i] = res;

                // 所有状态都变成fulfilled时返回的MyPromise状态就变成fulfilled
                if (count === promisesLength) {
                    // 返回所有promise对象的结果集合
                    resolve(valuesList)
                }
            }, err => {
                // 有一个被rejected时返回的MyPromise状态就变成rejected
                reject(err);
            })
        }
    })
}